package com.winderinfo.yikaotianxia.core.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import butterknife.ButterKnife;

public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(initLayoutId());
        ButterKnife.bind(this);
        initView();
        initData();
    }

    /**
     * 加载页面
     */
    protected abstract int initLayoutId();

    /**
     * 加载布局
     */
    protected abstract void initView();

    /**
     * 加载数据
     */
    protected abstract void initData();

    /**
     * 跳转至另一个Activity
     *
     * @param targetActivityClass 目标Activity
     */
    protected void openActivity(Class<?> targetActivityClass) {
        Intent intent = new Intent(this, targetActivityClass);
        startActivity(intent);
    }

    /**
     * 跳转至另一个Activity
     *
     * @param targetActivityClass 目标Activity
     * @param bundle              传递的参数
     */
    protected void openActivity(Class<?> targetActivityClass, Bundle bundle) {
        Intent intent = new Intent(this, targetActivityClass);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    /**
     * 跳转至另一个Activity并且关闭当前Activity
     *
     * @param targetActivityClass 目标Activity
     */
    protected void openActivityAndCloseThis(Class<?> targetActivityClass) {
        openActivity(targetActivityClass);
        this.finish();
    }

    /**
     * 跳转至另一个Activity并且关闭当前Activity
     *
     * @param targetActivityClass 目标Activity
     * @param bundle              传递的参数
     */
    protected void openActivityAndCloseThis(Class<?> targetActivityClass, Bundle bundle) {
        openActivity(targetActivityClass, bundle);
        this.finish();
    }

}
